//
// Created by Administrator on 2023/11/24.
//
#include "bits/stdc++.h"

using namespace std;

const int N = 20;

int n;
char Map[N][N];
bool col[N], p[N], q[N];

void dfs(int cur) {
    if (cur == n) {
        for (int i = 0; i < n; ++i) {
            cout << Map[i] << endl;
        }
        cout << endl;
        return;
    }
    for (int i = 0; i < n; ++i) {
        if (!col[i] && !p[i + cur] && !q[i - cur + n]) {
            Map[cur][i]='Q';
            col[i]=p[i+cur]=q[i-cur+n]= true;
            dfs(cur+1);
            Map[cur][i]='.';
            col[i]=p[i+cur]=q[i-cur+n]= false;
        }
    }

}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            Map[i][j] = '.';
        }
    }
    dfs(0);
}